<template>
    <!--引用表格-->
    <BasicTable @register="registerTable" :rowSelection="rowSelection">
      <!--插槽:table标题-->
      <template #tableTitle>
        <!-- <a-dropdown v-if="selectedRowKeys.length > 0">
          <template #overlay>
            <a-menu>
              <a-menu-item key="1" @click="batchHandleDelete">
                <Icon icon="ant-design:delete-outlined"></Icon>
                删除
              </a-menu-item>
            </a-menu>
          </template>
          <a-button
          >批量操作
            <Icon icon="ant-design:down-outlined"></Icon>
          </a-button>
        </a-dropdown> -->
      </template>
      <!--操作栏-->
      <template #action="{ record }">
        <TableAction :actions="getTableAction(record)" />
      </template>
    </BasicTable>
      <!--历史记录-->
    <historyModal @register="registerHistoryModal"></historyModal>
      <!--表单详情-->
  <itemSpModal @register="registerModal" @success="reload"></itemSpModal>

  <itemCheckModal @register="chenckModal" @success="reload"></itemCheckModal>
  </template>
  
  <script lang="ts" name="system-dsApply" setup>
    //ts语法
    import { ref, computed, unref } from 'vue';
    import { BasicTable, TableAction } from '/src/components/Table';
    import { useModal } from '/src/components/Modal';
    import { useMessage } from '/src/hooks/web/useMessage';
    import { columns, searchFormSchema } from './dsApply.data';
    import { useListPage } from '/@/hooks/system/useListPage';
    import { list} from './dsApply.api';
    import historyModal from '../myApply/components/historyModal.vue';
    import itemSpModal from './components/itemSpModal.vue';
    import itemCheckModal from './components/itemCheckModal.vue';
import { findLastIndex } from 'lodash-es';

    const [chenckModal, {openModal:chenckOpenModal}] = useModal();
    const [registerHistoryModal, {openModal:historyOpenModal}] = useModal();
    const [registerModal, {openModal:addOpenModal}] = useModal();
    const { createMessage } = useMessage();
    //字典model
    // const [registerModal, { openModal }] = useModal();
  
    // 列表页面公共参数、方法
    const { prefixCls, tableContext, onExportXls, onImportXls } = useListPage({
      designScope: 'dict-template',
      tableProps: {
        title: '审批待办',
        api: list,
        columns: columns,
        formConfig: {
          schemas: searchFormSchema,
        },
        actionColumn: {
          width: 300,
        },
      },
      //update-begin---author:wangshuai ---date:20220616  for：[issues/I5AMDD]导入/导出功能，操作后提示没有传递 export.url/import.url 参数------------
      // exportConfig: {
      //   name: '数据字典列表',
      //   url: getExportUrl,
      // },
      // importConfig: {
      //   url: getImportUrl,
      // },
      //update-end---author:wangshuai ---date:20220616  for：[issues/I5AMDD]导入/导出功能，操作后提示没有传递 export.url/import.url 参数--------------
    });
  
    //注册table数据
    const [registerTable, { reload, updateTableDataRecord }, { rowSelection, selectedRowKeys }] = tableContext;
  
    /**
     * 详情
     */
    // async function handleDetail(record) {
    //   openModal(true, {
    //     record,
    //     isUpdate: true,
    //   });
    // }
 
    /**
     * 成功回调
     */
    function handleSuccess() {
      // if (isUpdate) {
      //   updateTableDataRecord(values.id, values);
      // } else {
        console.log("回掉更新！")
        reload();
      // }
    }
    //委派
    function handleSpCancel(record: Recordable){
      chenckOpenModal(true, {
        record,
         isUpdate: 3,
         showFooter: true,
       });
    }
    //驳回
    function handleBHCancel(record: Recordable){
      chenckOpenModal(true, {
        record,
         isUpdate: 2,
         showFooter: true,
       });
    }
    //查看进度
    function handleHistory(record: Recordable){
      historyOpenModal(true, {
        record,
        isUpdate: true,
        showFooter: false,
      });
    }
    //表单数据
    function handleDetail(record: Recordable){
      addOpenModal(true, {
        record,
        isUpdate: true,
        showFooter: true,
      });
  }
    /**
     * 操作栏
     */
    function getTableAction(record) {
      let arrActionList=[];
          arrActionList.push( {label: '通过',onClick: handleDetail.bind(null, record)},)
          arrActionList.push( {label: '驳回',onClick: handleBHCancel.bind(null, record)},)
          arrActionList.push( {label: '委托他人代办',onClick: handleSpCancel.bind(null, record)},)
          arrActionList.push( {label: '审批历史',onClick: handleHistory.bind(null, record)},)
      return arrActionList;
      // return [
      //   {
      //     label: '编辑',
      //     onClick: handleEdit.bind(null, record),
      //   },
      //   {
      //     label: '删除',
      //     popConfirm: {
      //       title: '确定删除吗?',
      //       confirm: handleDelete.bind(null, record),
      //     },
      //   },
      // ];
    }
  </script>
  
  <style scoped></style>
  